﻿// See https://aka.ms/new-console-template for more information
using ConsoleApp1;
using Microsoft.Extensions.DependencyInjection;

Console.WriteLine("Hello, World!");

var serviceProvider = new ServiceCollection()
                .AddSingleton<IEventBus, EventBus>()
                .AddTransient<IEventHandler<DoSomethingEvent>, DoSomethingEventHandler>()
                .AddTransient<DoSomethingService>()
                .BuildServiceProvider();

var eventBus = serviceProvider.GetService<IEventBus>();
if (eventBus != null)
{
    //订阅
    eventBus.Subscribe(new DoSomethingEventHandler());
}

var doSomething = serviceProvider.GetRequiredService<DoSomethingService>();
    await doSomething.DoSomething(1, "John Doe");


//var serviceProvider = new ServiceCollection()
//                .AddSingleton<IEventBus, EventBus>()
//                .AddTransient<IEmailService, EmailService>()
//                .BuildServiceProvider();

//var eventBus = serviceProvider.GetService<IEventBus>();
//if (eventBus != null)
//{
//    //订阅
//    eventBus.Subscribe<EmailSendEvent, EmailSendEventHandler>();

//    var emailService = serviceProvider.GetRequiredService<EmailService>();
//    emailService.SendEmailAsync("test@example.com", "TestEmail", "Hello,thisisatestemail.");
//}

